<?php


namespace app\wApi\controller;
use app\common\service\UserService;
use app\common\utils\ResponseUtils;
use app\wApi\validate\UserLoginValidate;
use think\facade\Config;
use think\facade\Request;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("登录接口")
 */
class Login
{
    private $userService;
    public function __construct()
    {
        $this->userService=new UserService();
    }

    /**
     * @Apidoc\Title("登录接口")
     * @Apidoc\Desc("这里是一个描述")
     * @Apidoc\Url("wApi/login/index")
     * @Apidoc\Method("POST")
     * @Apidoc\Tag("登录")
     * @Apidoc\param("appid",type="string",require=true,desc="应用ID")
     * @Apidoc\Param("password",type="string",require=true,desc="用户密码")
     * @Apidoc\Param("timestamp",type="string",require=true,desc="时间戳")
     * @Apidoc\Param("username", type="string",require=true, desc="用户名")
     * @Apidoc\Param("sign",type="string",require=true,desc="验签值")
     * @Apidoc\Returned("data", type="array", desc="数据",
     *    @Apidoc\Returned("token", type="string", desc="登录身份令牌")
     * )
     */
    public function index(){

        try {
            validate(UserLoginValidate::class)->check(Request::param());

            $data=Request::post();
            $info=$this->userService->login($data);
            return ResponseUtils::retSuccessWithData($info);
        }catch (\Exception $exception){
            return ResponseUtils::retError($exception->getMessage());

        }
    }
}